package com.blb.proxy3;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JDKFactoryProxy implements InvocationHandler {
    //被代理对象
    private Object target;

    //创建代理对象
    public Object createProxyInstance(Object target){
        this.target=target;
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),this);

    }
    //调用被代理对象
    @Override
    public Object invoke(Object o, Method method, Object[] args) throws Throwable {
        System.out.println("给产品打广告");
        Object result = method.invoke(target, args);
        System.out.println("给产品做售后");
        return result;
    }
}
